<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./lib/vue.js"></script>
    <style></style>
  </head>

  <body>
    <div id="app">
      {{currentIndex}}
      <div>
        <div v-for="(v,i) in arr" :key="v.id" class="btn">
          <p @click="btnClick(i)">{{v.name}}</p>
        </div>

        <div>
          <ul v-for="(v,i) in arr" v-show="currentIndex == i ">
            <li v-for="item in v.children">{{item.name}}</li>
          </ul>
        </div>
      </div>
    </div>
    <script>
      new Vue({
        el: "#app",
        data() {
          return {
            currentIndex: 0,
            arr: [
              {
                id: 1,
                name: "社会新闻",
                children: [
                  { id: 2, name: "油价上涨了" },
                  { id: 3, name: "该核酸检测了" },
                ],
              },
              {
                id: 4,
                name: "娱乐新闻",
                children: [
                  { id: 5, name: "周杰伦发歌了" },
                  { id: 6, name: "周杰伦销量第一了" },
                ],
              },
            ],
          };
        },
        methods: {
          btnClick(i) {
            console.log(i);
            this.currentIndex = i;
          },
        },
      });
    </script>
  </body>
</html>
